
listWords = []

#read file
def readFile():

    global listWords

    def with_iter(iterable):
        with iterable as iter:
            for item in iter:
                yield item

    for line in with_iter(open('words.txt')):
        listWords.extend(line[:-1].split(' ')) if line[-1] == "\n" else listWords.extend(line.split(' '))

#calculate acerage sum
def calculateAverage():

    global listWords
    sumOfLenWords = 0
    readFile()

    for i in listWords:
        sumOfLenWords = len(i) + sumOfLenWords

    return sumOfLenWords/float(len(listWords))

#print calculate sum of words
print calculateAverage()
